package com.zhb.cloud.mail.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhb.cloud.base.BaseController;
import com.zhb.cloud.core.JsonReturn;
import com.zhb.cloud.mail.model.Email;
import com.zhb.cloud.mail.service.EmailService;
import com.zhb.cloud.utils.RandomUtils;

/**
 * @ClassName: EmailController
 * @author: zhb
 * @date: 2017年11月22日 下午9:27:57
 * @Description: 邮箱控制器
 */
@RestController
@RequestMapping("email")
public class EmailController extends BaseController {
	@Autowired
	private EmailService emailService;

	@PostMapping("sendEmail")
	public JsonReturn sendEmail() {
		String randomNumber = RandomUtils.randomNumber();
		Email mail = new Email();
		mail.setContent(randomNumber);
		mail.setEmail(new String[] { "1316783262@qq.com" });
		mail.setSubject("验证码邮件");
		return emailService.sendSimpleEmail(mail);
	}

	@PostMapping("sendTemplateEmail")
	public JsonReturn sendTemplateEmail() {
		String randomNumber = RandomUtils.randomNumber();
		Email mail = new Email();
		mail.setContent(randomNumber);
		mail.setEmail(new String[] { "1316783262@qq.com" });
		mail.setTemplate("validateCode");
		mail.setSubject("验证码邮件");
		return emailService.sendThymeleaf(mail);
	}

}
